﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using DFYE.Web.Models;
using JULONG.WEB.Library;
namespace DFYE.Web.Controllers
{
    public class guestBookController : Controller
    {
        DataSession<entityDBContainer, guestBook> db = new DataSession<entityDBContainer, guestBook>();

        //
        // GET: /guestBook/
        public ActionResult Index()
        {
            ViewData.Model = db.query()
                //.Where(d => d.able)
                .OrderByDescending(d => d.ID);
            return View();
        }

        [HttpPost]
        public ActionResult Index(FormCollection fc)
        {
            var gb = db.create();

            try
            {
                TryUpdateModel(gb);
                gb.able = false;
                gb.datetime = DateTime.Now;
                gb.ip = Request.UserHostAddress;
                db.insert(gb);
                TempData["info"] = "添加成功！";
            }

            catch (Exception e)
            {
                TempData["info"] = "添加失败！" + e.Message;
            }

            return RedirectToAction("Index");
        }
    }
}
